<?php
namespace Api\Model;

use Think\Model;

class GuwenLevelModel extends Model
{

    /**
     * 保存用户答案
     * @param $l_id
     * @param $answer
     * @param $uid
     * @param $avatar
     * @return mixed
     */

    public static function save_guwen_answer($l_id,$answer,$uid){

        $answer=explode(',',$answer);
        //获取问题-答案
        $data=[];
        foreach($answer as $k=>$v){
            $info=explode('-',$v);
            $title=M('questionnaire_title')->where(['id'=>$info[0]])->getField('title');
            $ans=M('questionnaire_answer')->where(['id'=>$info[1]])->getField('title');
           $data[$k]['question']=$title;
           $data[$k]['answen']=$ans;
        }
        $content=serialize($data);
        $level_info=M('guwen_level')->where(['id'=>$l_id])->find();
        $res=M('questionnaire_user_list')->add([
            'uid'=>$uid,
            'content'=>$content,
            'addtime'=>date('Y-m-d H:i:s',NOW_TIME),
            'level'=>$level_info['level'],
            'level_id'=>$l_id,
            'level_name'=>$level_info['name']
        ]);
        $avatar=M('members')->where(['uid'=>$uid])->getField('avatars');
        M('members')->where(['uid'=>$uid])->save(
            [
            //'utype'=>3,
            'guwen_qrimg'=>creat_qrcode('',$avatar)
          ]);

      return $res;
     //
    }



}